import Router from '@koa/router';
import TableConfigController from '@/controllers/TableConfigController';
import { auth, requirePermission } from '@/middlewares';
import { PermissionAction } from '@/types';

const router = new Router({
  prefix: '/api/table-configs',
});

/**
 * 动态表格配置路由
 */

// 获取表格配置列表
router.get(
  '/',
  auth,
  requirePermission('table_config', PermissionAction.READ),
  TableConfigController.list.bind(TableConfigController),
);

// 根据code获取表格配置
router.get(
  '/code/:code',
  auth,
  requirePermission('table_config', PermissionAction.READ),
  TableConfigController.getByCode.bind(TableConfigController),
);

// 获取单个表格配置
router.get(
  '/:id',
  auth,
  requirePermission('table_config', PermissionAction.READ),
  TableConfigController.getById.bind(TableConfigController),
);

// 创建表格配置
router.post(
  '/',
  auth,
  requirePermission('table_config', PermissionAction.CREATE),
  TableConfigController.create.bind(TableConfigController),
);

// 更新表格配置
router.put(
  '/:id',
  auth,
  requirePermission('table_config', PermissionAction.UPDATE),
  TableConfigController.update.bind(TableConfigController),
);

// 删除表格配置
router.delete(
  '/:id',
  auth,
  requirePermission('table_config', PermissionAction.DELETE),
  TableConfigController.delete.bind(TableConfigController),
);

// 批量删除表格配置
router.post(
  '/batch-delete',
  auth,
  requirePermission('table_config', PermissionAction.DELETE),
  TableConfigController.batchDelete.bind(TableConfigController),
);

export default router;
